#include<iostream>
using namespace std;
#include<queue>

struct TreeNode {
    int val;
    TreeNode *left;
    TreeNode *right;
    TreeNode() : val(0), left(nullptr), right(nullptr) {}
    TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
    TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
};

class Solution {
public:
    bool isCompleteTree(TreeNode* root) {
        if(root == NULL) {
            return true;
        }
        queue<TreeNode*> q;
        q.push(root);
        //叶子节点标志
        bool isLeaf  = false;
        while(!q.empty()){
            TreeNode* cur = q.front();
            //非叶节点 违法
            if(isLeaf && !(cur->left == NULL && cur->right == NULL)) {
                return false;
            }
            if(cur->left) q.push(cur->left);
            if(cur->right) q.push(cur->right);
            if(!cur->left && cur->right) {
                //有右子 无左子 违规
                return false;
            } else if(!cur->left || !cur->right){
                //左右子 不全 后续必须全部为叶子节点
                isLeaf = true;
            }
            q.pop();
        }
        return true;
    }
};

int main() {
    return 0;
}